package com.woniu.microprojectserver.othermag.service.impl;

import com.woniu.microcommonsserver.entity.BuildInfoEntity;
import com.woniu.microcommonsserver.entity.SpaceInfoEntity;
import com.woniu.microprojectserver.othermag.mapper.ProjectMapper;
import com.woniu.microprojectserver.othermag.service.IProjectService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

/**project的业务逻辑实现
 * @author: hejie
 * @date: 2021/1/30 8:01
 * @description:
 */
@Service
public class ProjectServiceImpl implements IProjectService {

    @Resource
    private ProjectMapper projectMapper;



    /**
     * 根据“build_info中的id”、rank为1的id  查询属于该build某个building下的所有房间(如“水青花都小区-11号楼-5单元-8层-802”，即rank为4的SpaceInfoEntity)
     * @author hejie
     * @param bId：build_info中的id。
     * @param buildingId 在space_info中rank为1，如“13号楼”
     * @param buildingAbbreviation  space_info中rank为1的简称，如“13号楼”
     * @return
     */
    @Override
    public List<SpaceInfoEntity> findRoomByBidAndBuildingId(Long bId, Long buildingId, String buildingAbbreviation){
        return projectMapper.findRoomByBidAndBuildingId(bId, buildingId, buildingAbbreviation);
    }

    /**
     * 根据“build_info中的id”查询属于该build的所有building(如3号楼，即rank为1的SpaceInfoEntity)
     * @author hejie
     * @param bId：build_info中的id
     * @return
     */
    @Override
    public List<SpaceInfoEntity> findBuildingByBid(Long bId){
        return projectMapper.findBuildingByBid(bId);
    }

    /**
     * 查询所有的build
     * @return
     */
   @Override
   public List<BuildInfoEntity> findAllBuild() {
        return projectMapper.findAllBuild();
   }

    /**——为了解决 初始化roomId
     * 查询1个房间的id（rank为4）：13（为了给roomId初始化）
     * @author hejie
     * @return
     */
   @Override
   public Long findAId(){
       return projectMapper.findAId();
   }

    /**查询所有的 房间（就是房间的List）：List<SpaceInfoEntity>
     * 根据“build_info中的id”查询属于该build的所有building下的所有房间
    * @param bId 小区的id
    * @param buildingId 楼栋的id
    * @param buildingAbbreviation 楼栋
    * @param roomName 房间的名字（在前端传入的是 “3-5-1002”，impl处需要 把它转为“xxx小区-3号楼-5单元-10层-1002”）
     * @return
     */
   @Override
   public List<SpaceInfoEntity> findRoomsByParams(Long bId,
                                                  Long buildingId,
                                                  String buildingAbbreviation,
                                                  String roomName){
       return projectMapper.findRoomsByParams(bId,
                                               buildingId,
                                               buildingAbbreviation,
                                               roomName);
   }


    /**
     * 根据 id，查询spaceInfo
     * @param id
     * @return
     */
   @Override
   public SpaceInfoEntity findSpaceById(Long id){
       return projectMapper.findSpaceById(id);
    }
}
